{
语法百题 解题报告：
 http://git.oschina.net/et0662/sznoi-grammar/ 
}

{CE 我也是醉了}
{
type
	node=record
		data:integer;
		next:^node;
		end;

var
	head,tail,temp,p:^node;
	n,m,i:integer;
begin
	readln(n,m);
	new(head);
	head^.next:=nil;
	tail:=nil;
	for i:=1 to n do
	begin
		new(temp);
		temp^.data:=i;
		if(head^.next=nil)then
			head^.next:=temp;
		if(tail<>nil)then
			tail^.next:=temp;
		tail:=temp;
	end;
	tail^.next:=head^.next;
	i:=0;
	temp:=head;
	while( temp^.next<> temp)do
	begin
		inc(i);
		if(i=m)then
		begin

			p:=temp^.next;
			temp^.next:=temp^.next^.next;
			dispose(p);
			i:=0;
		end
		else
		begin
			temp:=temp^.next;
		end;
	end;
	writeln(temp^.data);
	dispose(temp);
	dispose(head);
end.
}

{这样提交才行~}
{
type
	pnode=^node;
    node=record
        data:integer;
        next:pnode;
        end;

var
    head,tail,temp,p:^node;
    n,m,i:integer;
begin
    readln(n,m);
    new(head);
    head^.next:=nil;
    tail:=nil;
    for i:=1 to n do
    begin
        new(temp);
        temp^.data:=i;
        if(head^.next=nil)then
            head^.next:=temp;
        if(tail<>nil)then
            tail^.next:=temp;
        tail:=temp;
    end;
    tail^.next:=head^.next;
    i:=0;
    temp:=head;
    while( temp^.next<> temp)do
    begin
        inc(i);
        if(i=m)then
        begin
            p:=temp^.next;
            temp^.next:=temp^.next^.next;
            dispose(p);
            i:=0;
        end
        else
        begin
            temp:=temp^.next;
        end;
    end;
    writeln(temp^.data);
    dispose(temp);
    dispose(head);
end.
}



var
	b:array of boolean;
	n,m,i,j,p:integer;
begin
	readln(n,m);
	setlength(b,n+1);
	for i:=1 to n do
	begin
		b[i]:=true;
	end;
	j:=n;
	i:=0;
	p:=1;
	while(j<>1)do
	begin
		if(b[p]) then
		begin
			inc(i);
			if(i=m)then
			begin
				b[p]:=false;
				dec(j);
				i:=0;
			end;
		end;
		inc(p);
		if(p>n)then
			p:=1;
	end;
	for i:=1 to n do
	begin
		if(b[i])then
			writeln(i);
	end;
end.